package net.stuffrepos.bricknetcenter.plugins.bricklink;

import java.net.MalformedURLException;
import java.net.URL;
import net.stuffrepos.bricknetcenter.http.HttpRequest;

/**
 *
 * @author Eduardo H. Bogoni <eduardobogoni@gmail.com>
 */
public abstract class BrickLinkCatalogDownloadRequest implements HttpRequest {

    private final String selDim = "Y";
    private final String selWeight = "Y";
    private final String selYear = "Y";
    private final String downloadType = "X";
    private ViewType viewType;
    private String itemTypeInv;
    private String itemType;
    private String itemNo;

    public BrickLinkCatalogDownloadRequest(ViewType viewType, String itemType, String itemTypeInv, String itemNo) {
        this.viewType = viewType;
        this.itemType = itemType;
        this.itemTypeInv = itemTypeInv;
        this.itemNo = itemNo;
    }

    @Override
    public URL getUrl() {
        try {
            return new URL("http://www.bricklink.com/catalogDownload.asp?a=a");
        } catch (MalformedURLException ex) {
            throw new RuntimeException(ex);
        }
    }

    @Override
    public URL getReferer() {
        try {
            return new URL("http://www.bricklink.com/catalogDownload.asp");
        } catch (MalformedURLException ex) {
            throw new RuntimeException(ex);
        }
    }

    @Override
    public int getPriority() {
        return 0;
    }

    @Override
    public Method getMethod() {
        return Method.Post;
    }

    @Override
    public PostParameter[] getPostParameters() {
        return new PostParameter[]{
                    new PostParameter("selDim", selDim),
                    new PostParameter("selWeight", selWeight),
                    new PostParameter("selYear", selYear),
                    new PostParameter("downloadType", downloadType),
                    new PostParameter("viewType", viewType.optionValue()),
                    new PostParameter("itemType", itemType),
                    new PostParameter("itemTypeInv", itemTypeInv),
                    new PostParameter("itemNo", itemNo),};
    }

    public static enum ViewType {

        CatalogItems("0"),
        ItemTypes("1"),
        Categories("2"),
        Colors("3"),
        Inventory("4"),
        PartAndColorCodes("5");
        private String optionValue;

        ViewType(String optionValue) {
            this.optionValue = optionValue;
        }

        public String optionValue() {
            return this.optionValue;
        }
    }
}
